package cl.uchile.sketchpad.persistance.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cl.uchile.sketchpad.persistance.model.Activity;

@Repository
public class ActivityDaoImpl implements ActivityDao {

	@PersistenceContext
	private EntityManager em; 
	
	@Override
	@Transactional(readOnly = true)
	public List<Activity> getAll() {
		TypedQuery<Activity> q = em.createQuery("from Activity", Activity.class);
		return q.getResultList();
	}

	@Override
	public Activity findById(Integer id) {
		return em.find(Activity.class, id);
	}

	@Override
	public void persist(Activity activity) {
		em.persist(activity);	
	}

}
